package com.example.lenovo.qm;

import androidx.appcompat.app.AppCompatActivity;
import androidx.drawerlayout.widget.DrawerLayout;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {
    private TextView tv;
    private GridView gv;
    private ArrayList<GridViewItemData> mArrayGridViewItemData;
    private GridViewAdapter gridViewAdapter;
    private Intent intents[]=new Intent[20];
    private DrawerLayout dl;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);
        initData();
        initView();
    }

    private void initView() {

        tv=findViewById(R.id.tv);
        tv.setOnClickListener(listener);
        dl=findViewById(R.id.dl);

        gv=findViewById(R.id.gv);

        gv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                startActivity(intents[position]);
            }
        });


    }
    private View.OnClickListener listener=new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            switch (v.getId()){
                case R.id.tv:
                    gridViewAdapter=new GridViewAdapter(MainActivity.this,mArrayGridViewItemData);
                    gv.setAdapter(gridViewAdapter);
                    dl.closeDrawers();

                    break;


            }
        }
    };
    protected void initData() {
        intents[0] = new Intent(this, First.class);
        intents[1] = new Intent(this, Second.class);
        intents[2] = new Intent(this, Third.class);
        intents[3] = new Intent(this, Four.class);
        intents[4] = new Intent(this, Five.class);

        mArrayGridViewItemData = new ArrayList<GridViewItemData>();
        mArrayGridViewItemData.add(new GridViewItemData(R.mipmap.a1,"作业1"));
        mArrayGridViewItemData.add(new GridViewItemData(R.mipmap.a2,"作业2"));
        mArrayGridViewItemData.add(new GridViewItemData(R.mipmap.a3,"作业3"));
        mArrayGridViewItemData.add(new GridViewItemData(R.mipmap.a4,"作业4"));
        mArrayGridViewItemData.add(new GridViewItemData(R.mipmap.a5,"作业5"));
        mArrayGridViewItemData.add(new GridViewItemData(R.mipmap.a6,"作业6"));
        mArrayGridViewItemData.add(new GridViewItemData(R.mipmap.a7,"作业7"));
        mArrayGridViewItemData.add(new GridViewItemData(R.mipmap.a8,"作业8"));
        mArrayGridViewItemData.add(new GridViewItemData(R.mipmap.a9,"作业9"));
        mArrayGridViewItemData.add(new GridViewItemData(R.mipmap.a10,"作业10"));
        mArrayGridViewItemData.add(new GridViewItemData(R.mipmap.a11,"作业11"));
        mArrayGridViewItemData.add(new GridViewItemData(R.mipmap.a12,"作业12"));
        mArrayGridViewItemData.add(new GridViewItemData(R.mipmap.a13,"作业13"));
        mArrayGridViewItemData.add(new GridViewItemData(R.mipmap.a14,"作业14"));
        mArrayGridViewItemData.add(new GridViewItemData(R.mipmap.a15,"作业15"));
        mArrayGridViewItemData.add(new GridViewItemData(R.mipmap.a16,"作业16"));
        mArrayGridViewItemData.add(new GridViewItemData(R.mipmap.a17,"作业17"));
        mArrayGridViewItemData.add(new GridViewItemData(R.drawable.exit,"作业18"));
        mArrayGridViewItemData.add(new GridViewItemData(R.mipmap.a19,"作业19"));


    }

}